package org.sction.util;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import net.sf.json.JSON;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

/**
 * @author 作者 : sorc
 * @version 创建时间：2012-2-17 下午12:03:57
 * 
 *          类说明
 */
public class JSONUtils {
	public static JSON toJSON(Object obj) {
		if (obj instanceof java.util.Collection<?>) {
			return JSONArray.fromObject(obj);
		} else {
			return JSONObject.fromObject(obj);
		}
	}

	public static JSON toJSON(Object obj, JsonConfig jsonConfig) {
		if (obj instanceof java.util.Collection<?>) {
			return JSONArray.fromObject(obj, jsonConfig);
		} else {
			return JSONObject.fromObject(obj, jsonConfig);
		}
	}

	@SuppressWarnings("rawtypes")
	public static void main(String[] args) {
		JsonConfig jsonConfig = new JsonConfig();
		jsonConfig.registerJsonValueProcessor(Date.class,
				new DateJsonValueProcessor());
		jsonConfig.registerJsonValueProcessor(java.sql.Date.class,
				new SQLDateJsonValueProcessor());
		jsonConfig.registerJsonValueProcessor(java.sql.Timestamp.class,
				new TimestampJsonValueProcessor());
		Map map = StringUtils
				.toMap("{mp_id=1, mp_name=123, mp_url=, mp_type=1, mp_opentype=, image=, remark=, mid=, sn=0, mp_enable=1}");
		List<Map> list = new ArrayList<Map>();
		list.add(map);
	}
}
